﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using flightquiz.Data;

namespace flightquiz
{
    public partial class Main : Form
    {
        private Excercise _excercise = new Excercise();

        public Main()
        {
            InitializeComponent();
        }

        private void Main_Load(object sender, EventArgs e)
        {
            _excercise.Load();

            lstItems.Items.Clear();
            foreach (var question in _excercise.Questions)
            {
                lstItems.Items.Add(question);
            }
            lstItems.SelectedIndex = 0;

            foreach (var paper in _excercise.Papers)
            {
                btnChakanShijuan.DropDownItems.Add(paper.Name);
            }

            btnChakanTiku.Checked = true;
            btnShengchengKaojuan.Checked = false;
        }

        private void lstItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            Question question = (lstItems.SelectedItem as Question);
            ctlBrowser.DocumentText = question.ToHTML();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            ctlBrowser.ShowPrintPreviewDialog();
        }

        private void btnChakanTiku_Click(object sender, EventArgs e)
        {
            ctlSplit.Panel1Collapsed = false;
            lstItems.SelectedIndex = 0;
            lstItems_SelectedIndexChanged(lstItems, EventArgs.Empty);
        }

        private void btnShengchengKaojuan_Click(object sender, EventArgs e)
        {
            btnChakanTiku.Checked = false;
            btnShengchengKaojuan.Checked = true;

            Quiz quiz = new Quiz();
            if (quiz.ShowDialog() == DialogResult.OK)
            {
                Excercise paper = _excercise.BuildPaper(quiz.QuizName, quiz.QuizCount);
                ctlBrowser.DocumentText = paper.ToHTML();

                btnChakanShijuan.DropDownItems.Add(paper.Name);

                ctlSplit.Panel1Collapsed = true;
            }
        }
        private void btnChakanShijuan_DropDownItemClicked_1(object sender, ToolStripItemClickedEventArgs e)
        {
            ctlSplit.Panel1Collapsed = true;
            ctlBrowser.DocumentText = _excercise.FindPaper(e.ClickedItem.Text).ToHTML();
        }
    }
}
